<script>
    var page_list = "gas_card_list_search";
    $(function() {
        $("body").layout();
        grid_init($("#grid"),{
            singleSelect: false,
            columns:[[
                { field: 'o.gasCardId', checkbox: true, title: '加油卡ID'},
                { field: 'o.gasCardNo', title: '加油卡号',width: 120},
                { field: 'u.personName', title: '持卡人',width: 120},
                { field: 'o.gasCardTime', title: '持卡时间',width: 120},
                { field: 'area.areaName', title: '所属区域',width: 120},
                { field: 'car.carLicense', title: '车号',width: 120},
                { field: 'o.cardType', title: '类型',width: 120,formatter: function(value,row,index){
                    if (value=="1"){
                        return "分卡";
                    } else if(value=="0"){
                        return "主卡";
                    }
                    return value;
                }},
                { field: 'o.cardFlag', title: '状态',width: 120,formatter: function(value,row,index){
                    if (value=="1"){
                        return "启用";
                    } else if(value=="0"){
                        return "禁用";
                    }
                    return value;
                }},
                { field: 'o.balance', title: '余额',width: 150},
                { field: 'o.createTime', title: '创建时间',width: 150},
                { field: 'opUser.personName', title: '创建操作人',width: 120},
                { field: 'o.modifyTime', title: '修改时间',width: 150},
                { field: 'mUser.personName', title: '修改操作人',width: 120}]],
            _order:"o.createTime desc",
            _append: [],//隐藏列
            _page: page_list,
            _table: "erp_gascard as o left join hr_person as u on o.leader = u.personId " +
                    "left join erp_area as area on o.areaId = area.areaId " +
                    "left join erp_carinfo as car on o.carId = car.carId " +
                    "left join hr_person as opUser on o.createUserId = opUser.personId " +
                    "left join hr_person as mUser on o.modifyMan = mUser.personId",
            _exportTitle: false,
            _context_handle: [{
                text: "确定",
                auth: "update",
                icon: "icon-ok",
                handle: function(index,row){
                    var self = this;
                    var gasCardId = self.getFieldValue(row,"o.gasCardId");//加油卡ID
                    var gasCardNo = self.getFieldValue(row,"o.gasCardNo");//加油卡号
                    var balance = self.getFieldValue(row,"o.balance");//余额

                    parent.chooseRollbackGasCard({
                        "gasCardId":gasCardId,
                        "gasCardNo":gasCardNo,
                        "balance":balance
                    });
                    parent.j_closeWin();
                }
            },{
                text: "详情",
                icon: "icon-info",
                handle: function(index,row){
                    j_showWin({url:'erp/gasCard/info.html?keyId='+this.getFieldValue(row,"o.gasCardId"),title:'加油卡信息',iconCls: 'icon-form-info'})
                }
            }],
            toolbar: '#grid_toolbar',
            searchDiv: '#grid_search'
        });
    });

    //所属区域
    $('#areaName').inputgrid({
        idField:'o.areaId',
        textField:'o.areaName',
        multiple: false,
        searchField:['o.areaNo','o.areaName'],//查询字段多字段匹配
        queryParamsFun:function(input){
            var param = [{field: 'o.deleteFlag', value: '0' },{field: 'o.state', value: '1' }];
            return param;
        },
        columns:[[
            { field: 'o.areaNo', title: '编号',width:60},
            { field: 'o.areaName', title: '区域名称',width:120 },
            { field: 'o.dutyMan', title: '区域负责人',width:120 }
        ]],
        _page: parent.page_list,
        _append: ['o.areaId'],//隐藏列
        _table: "erp_area o"
    });

    //员工单选列表
    $('#personName').inputgrid({
        idField:'o.personId',
        textField:'o.personName',
        searchField:['o.personNo','o.personName'],//查询字段多字段匹配
        queryParamsFun:function(input){
            var param = [{field: 'o.deleteFlag', value:'0'}];
            //排除超级管理员
            param.push({field: 'o.personId', value: '1', like: false, not: true})
            return param;
        },
        columns:[[
            { field: 'o.personNo', title: '员工编号'},
            { field: 'o.personName', title: '员工姓名'}
        ]],
        _page: parent.page_list,
        _append: ["o.personId"],//隐藏列
        _table: "hr_person as o"
    });
</script>
<div id="grid_search" data-options="region:'north',height:'auto',hideExpandTool: true,hideCollapsedContent: false,collapsedContent:function(){return '查询条件(已隐藏)'}" style="border-top:none;border-left:none;border-right:none;" class="search-form">
    <input type="hidden" name="o.deleteFlag" value="0"/>
    <div class="div-item">
        <div class="div-label">加油卡号：</div>
        <input name="o.gasCardNo" type="text" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">所属区域：</div>
        <input type="hidden" id="areaId" name="o.areaId" clear/>
        <input type="text" id="areaName" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">持卡人：</div>
        <input type="hidden" id="leader" name="o.leader" clear/>
        <input type="text" id="personName" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">类型：</div>
        <select name="o.cardType" id="cardType" style="width: 60px;" value="${cardType}" clear>
            <option value="" >所有</option>
            <option value="0" >主卡</option>
            <option value="1" >分卡</option>
        </select>
        <div class="div-label" style="width: 80px;">状态：</div>
        <select name="o.cardFlag" id="cardFlag" style="width: 60px;" value="${cardFlag}" clear>
            <option value="1" >启用</option>
        </select>
    </div>

</div>
<div data-options="region:'center',title:false,border:false" id="divCenter" style="">
    <table id="grid"></table>
</div>
<div id="grid_toolbar" style="display:none;padding:3px;">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'layout-button-up'" onclick="var button=$(this);if(button.linkbutton('options').iconCls=='layout-button-up'){$('body').layout('collapse','north');button.linkbutton({iconCls:'layout-button-down'})}else{$('body').layout('expand','north');button.linkbutton({iconCls:'layout-button-up'})}button.linkbutton('disable');setTimeout(function(){button.linkbutton('enable');},200)" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-help'" id="help" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-button-refresh'" onclick="grid_get('grid')[0].search(true)" style="float:right">重置</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="grid_get('grid')[0].search()" style="float:right">查询</a>
</div>